package com.time.hellotime.components.popup;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.time.hellotime.R;
import com.time.hellotime.base.BasePW;
import com.time.hellotime.viewmodel.DynamicsViewModel;

/**
 * 分享的PW
 * Author: Created by deng on 2016/8/16.
 * E-mail: tx16bing@163.com
 */
public class SharePW extends BasePW implements View.OnClickListener {

    private Context mContext;

    public SharePW(Context context, ViewGroup view) {
        this.mContext = context;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.pw_select_share, view, false);
        assignViews(mView);
        setContentView(mView);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setFocusable(true);
        setOutsideTouchable(true);
        this.setAnimationStyle(R.style.Pw_Bottom_Animation);
        ColorDrawable dw = new ColorDrawable(0x80000000);
        this.setBackgroundDrawable(dw);
    }

    private void assignViews(View mView) {

        mView.findViewById(R.id.iv_share_wx_friend).setOnClickListener(this);
        mView.findViewById(R.id.iv_share_wx_publish).setOnClickListener(this);
        mView.findViewById(R.id.iv_share_qq).setOnClickListener(this);
        mView.findViewById(R.id.iv_share_zone).setOnClickListener(this);
        mView.findViewById(R.id.iv_share_wb).setOnClickListener(this);
        mView.findViewById(R.id.iv_share_moe).setOnClickListener(this);
        mView.findViewById(R.id.tv_cancel).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (onItemClickListener != null) {
            switch (view.getId()) {

                case R.id.iv_share_wx_friend:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_wx), "");
                    dismiss();
                    break;

                case R.id.iv_share_wx_publish:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_wx_publish), "");
                    dismiss();
                    break;

                case R.id.iv_share_qq:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_qq), "");
                    dismiss();
                    break;

                case R.id.iv_share_zone:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_qq_zone), "");
                    dismiss();
                    break;

                case R.id.iv_share_wb:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_wb), "");
                    dismiss();
                    break;

                case R.id.iv_share_moe:
                    onItemClickListener.onItemClick(getType(R.integer.share_type_more), "");
                    dismiss();
                    break;

                case R.id.tv_cancel:
                    dismiss();
                    break;

                default:
                    dismiss();
                    break;

            }
        }
    }

    private int getType(int id){
        return mContext.getResources().getInteger(id);
    }

}
